package com.xbongbong.saas.enums.dictionary;

import com.xbongbong.i18n.util.I18nMessageUtil;
import lombok.Getter;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;

/**
 * 附近客户距离
 * @author haibin.zhang
 * @version v1.0
 * @date 2019/2/26 11:10
 * @since v1.0
 */
@Getter
public enum DistanceEnum {
    //1：500米以内，2：1公里以内，3：5公里以内，4：10公里以内，5：所有
    HALF_KILOMETER("1", "enum.distance.attr.half_kilometer","halfKilometer",500),
    KILOMETER("2", "enum.distance.attr.kilometer","kilometer",1000),
    FIVE_KILOMETER("3", "enum.distance.attr.five_kilometer","fiveKilometer",5000),
    TEN_KILOMETER("4", "enum.distance.attr.ten_kilometer","tenKilometer",10000),
//    GREATER_TEN_KILOMETER(5,"10千米外","greaterTenKilometer"),
    ;
    private String code;
    private String attr;
    private String alias;
    private Integer distance;

    DistanceEnum(String code, String attr, String alias,Integer distance) {
        this.code = code;
        this.attr = attr;
        this.alias = alias;
        this.distance = distance;
    }

    public static List<DistanceEnum> getList() {
        return new ArrayList<>(Arrays.asList(values()));
    }

    public static Integer getByCode(String distance) {
        for (DistanceEnum distanceEnum : values()){
            if (Objects.equals(distanceEnum.getCode(),distance)){
                return distanceEnum.distance;
            }
        }
        return null;
    }

    public String getAttr() {
        return I18nMessageUtil.getMessage(attr);
    }
}
